<?php
namespace Admin\Controller;
use Think\Controller;
class BaseController extends Controller{
    public function __construct()
    {
        //必须先调用父类的构造方法
        parent::__construct();
        //判断登录

        if(!session('id'))
            $this->error('必须先登录',redirect(U('Login/login')));
        //所有管理员都可以访问首页
        if(CONTROLLER_NAME == 'Index')
            return true;
        $priModel = D('Privilege');
        if(!$priModel->chkPri())
        {
            $this->error('无权访问！');
        }

        if(session("admin.company_id"))
        {
            $where['company_id'] = session("admin.company_id");
        }
        //默认时间是当前的一个月以内
//        $lastmonth = time()-(86400*30);
//        $where['yueyu_time'] = array(array("egt",date("Y-m-d H:i:s",$lastmonth)),array("elt",date("Y-m-d H:i:s",time())));
        $this->yuyuecount = M("yuyue")->where($where)->count();  //预约人数统计

//        unset($where['yueyu_time']);
//        $where['start_time'] = array("lt",date("Y-m-d H:i:s",time()));
//        $where['end_time'] = array("gt",date("Y-m-d H:i:s",time()));
        $this->membercount = M('member')->where($where)->count(); //客户人数

        $memberbirthday = M('member')->where($where)->select();
        $ss = 0;
        foreach ($memberbirthday as $v)
        {

            $bir = date("Y",time()).substr($v['birthday'],4);
            $strtotime = strtotime($bir);
//            var_dump($strtotime);
            $nowtime = time()+(86400*30);
            if($nowtime>$strtotime)
            {
                $ss++;
            }
        }
        $this->memberbirthday =  $ss;
    }



}